package cn.xxc.basic.service.impl;

import cn.xxc.basic.mapper.BaseMapper;
import cn.xxc.basic.query.BaseQuery;
import cn.xxc.basic.service.BaseService;

import cn.xxc.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadByid(Long id) {
        return baseMapper.loadByid(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Override
    public Integer queryCount(BaseQuery query) {
        return baseMapper.queryCount(query);
    }

    @Override
    public List<T> queryData(BaseQuery query) {
        return baseMapper.queryData(query);
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        try {
            Integer totals=baseMapper.queryCount(query);
            List<T> data=baseMapper.queryData(query);
            return new PageList<>(totals,data);
        }catch (Exception e){
            System.out.println(e.getMessage());
            return new PageList<>();
        }
    }

    @Override
    @Transactional
    public void patchDel(Long[] ids) {
        baseMapper.patchDel(ids);
    }
}
